<% @page_title = "Search user" %>
<%= stylesheet_link_tag "admin/form", :media => "all" %>
<%= stylesheet_link_tag "admin/list-items", :media => "all" %>

<div class="search-form">
	<h1>Search user</h1>
	<%= form_tag(:controller => "admin/user", :action => "search") do |f| %>
	<p>
		<%= text_field_tag(:keyword) %>&nbsp;
		<%= select_tag(:cate, options_for_select([['ID', 0], ['Username', 1], ['Card ID', 2], ['Email', 3], ['Phone', 4], ['Full Name', 5]], -1)) %>&nbsp;
		<%= submit_tag "Search", :name => 'search' %>
	</p>
	<% end %><!-- End form -->
</div><!-- End .create-faculty-form -->

<% if @results_list %>
<div class='search-result' style='margin-top: 30px'>
	<h1>Results</h1>
	<% if @results_list.size > 0 %>
		<table>
			<tr>
				<th>ID</th>
				<th>Full Name</th>
				<th>Card ID</th>
				<th>Username</th>
				<th>Student/Staff ID</th>
				<th>Reader group</th>
				<th>Faculty</th>
				<th>Phone</th>
				<th class='action'>Action</th>
			</tr>
			<% order = 0 %>
			<% @results_list.each do |user| %>
				<tr <% if order % 2 == 0 %><%= "class='alt'" %><% end %> ><% order += 1 %>
					<td class='id'><%= user.id %></td>
					<td><%= link_to user.fullname, :controller => "admin/user", :action => "view", :id => user.id %></td>
					<td><%= user.card_id %></td>
					<td><%= user.username %></td>
					<td><%= user.reader_id %></td>
					<td><%= Role.getRoleName(user.role_id) %></td>
					<td><%= Faculty.getFacultyName(user.faculty_id) %></td>
					<td><%= user.phone %></td>
					<td class='action'>
						<%= link_to image_tag('icons/view-icon.png'), :controller => "admin/user", :action => "view", :id => user.id %>&nbsp;
						<%= link_to image_tag('icons/edit-icon.png'), :controller => "admin/user", :action => "edit", :id => user.id %>&nbsp;
						<%= link_to image_tag('icons/delete-icon.png'), {:controller => "admin/user", :action => "delete", :id => user.id}, :method => "delete", :data => {:confirm => "Bạn có chắc chắn muốn xóa?"} %>
					</td>
				</tr>
			<% end %>
		</table>
		<div class='paginator' style='margin-left:100px'><%= will_paginate @results_list %></div>
	<% else %>
		<h3 style='color: red'>No result found</h3>
	<% end %>
</div><!-- End .search-result -->
<% end %>
